import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router'
import viewsRouter from './views'
import pageRouter from './page'
import store from "@/store"

// 对RouteRecordRaw类型进行扩展
export type AddRouteRecordRaw = RouteRecordRaw & {
    hidden?: boolean
}

const router = createRouter({
    history: createWebHashHistory(),
    routes: [...viewsRouter, ...pageRouter] as AddRouteRecordRaw[]
})
router.beforeEach(async (to) => {
    if (!store.getters["auth/getIsLogin"] && to.path !== '/login') {
        return {path: '/login'}
    }
})
export default router